// pages/dashboard/dashboard.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    acctList: [
      { src: '', icon: 'icon-yuebiao', color: '#A2EF4D', name: '余额表', url: '/accounting/account_balance/account_balance?entity=all_account_summary', },
      { src: '', icon: 'icon-mingxizhang', color: '#0F40F5', name: '明细账', url: '/accounting/subject_detail/subject_detail?entity=all_voucher_statistics', },
      { src: '', icon: 'icon-huizongbiao', color: '#FFBF6B', name: '汇总表', url: '/accounting/account_summary/account_summary?entity=all_account_summary_total', },
      { src: '', icon: 'icon-lirunbiao', color: '#54BCBD', name: '利润表', url: '/accounting/income_statement/income_statement', },
      { src: '', icon: 'icon-zichanfuzhaibiao', color: '#4095E5', name: '资产负债表', url: '/accounting/balance_sheet/balance_sheet', },
    ],

    financeList: [],      // 财务分析报表
    businessList: [],     // 业务分析报表
  },

  // nav 跳转
  navTo(e) {
    let { url, } = e.currentTarget.dataset
    if(!url) return
    wx.navigateTo({
      url: url,
    })
  },

  // 接口
  getFinanceList() {
    let post = {
      abstract: '',
      report_name: '',
      report_type: '财务分析报表',
      row_id: 0,
    }
    wx.$post(1, 'StatsReport/select_all_report', post).then(res => {
      if(res.errcode !== 0) return
      let rows = res.data.row
      rows.forEach(item => item.url = `/pages/statistics_report/statistics_report?reportid=${item.row_id}&reportname=${item.report_name}&width=${item.width}&height=${item.height}`)
      this.setData({
        financeList: rows,
      })
    })
  },
  getBusinessList() {
    let post = {
      abstract: '',
      report_name: '',
      report_type: '业务分析报表',
      row_id: 0,
    }
    wx.$post(1, 'StatsReport/select_all_report', post).then(res => {
      if(res.errcode !== 0) return
      let rows = res.data.row
      rows.forEach(item => item.url = `/pages/statistics_report/statistics_report?reportid=${item.row_id}&reportname=${item.report_name}&width=${item.width}&height=${item.height}`)
      this.setData({
        businessList: rows,
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.$setBarTitle();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getFinanceList()
    this.getBusinessList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
})
